<template>
  <div class="no-project-access">
    <div class="error-container">
      <div class="error-icon">
        <i class="el-icon-warning-outline" />
      </div>
      <div class="error-content">
        <h2>无项目SOP访问权限</h2>
        <p class="error-description">
          您当前项目没有配置任何SOP分类，无法使用AI智能SOP功能。
        </p>
        <div class="error-details">
          <p>可能的原因：</p>
          <ul>
            <li>您的项目尚未关联任何SOP分类</li>
            <li>项目管理员需要为您的项目配置SOP权限</li>
            <li>SOP分类可能被禁用或删除</li>
          </ul>
        </div>
        <div class="action-buttons">
          <el-button type="primary" @click="contactAdmin">
            <i class="el-icon-message" />
            联系管理员
          </el-button>
          <el-button @click="refreshPage">
            <i class="el-icon-refresh" />
            刷新页面
          </el-button>
          <el-button v-if="canManage" @click="goToManagement">
            <i class="el-icon-setting" />
            SOP管理
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NoProjectAccess',
  computed: {
    canManage() {
      // 检查用户是否有管理权限
      const roles = this.$store.getters.roles || []
      return roles.includes('admin') || roles.includes('ai_model_manager')
    }
  },
  methods: {
    contactAdmin() {
      this.$message.info('请联系系统管理员为您的项目配置SOP访问权限')
    },
    refreshPage() {
      window.location.reload()
    },
    goToManagement() {
      this.$router.push('/crm/aimodeltreemanager/')
    }
  }
}
</script>

<style scoped>
.no-project-access {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  background-color: #f5f7fa;
}

.error-container {
  text-align: center;
  background: white;
  padding: 60px 40px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  max-width: 600px;
  width: 90%;
}

.error-icon {
  font-size: 80px;
  color: #E6A23C;
  margin-bottom: 30px;
}

.error-content h2 {
  color: #303133;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 16px;
}

.error-description {
  color: #606266;
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 30px;
}

.error-details {
  text-align: left;
  background: #fdf6ec;
  padding: 20px;
  border-radius: 6px;
  margin-bottom: 30px;
  border-left: 4px solid #E6A23C;
}

.error-details p {
  color: #E6A23C;
  font-weight: 600;
  margin-bottom: 10px;
}

.error-details ul {
  color: #606266;
  margin: 0;
  padding-left: 20px;
}

.error-details li {
  margin-bottom: 8px;
  line-height: 1.4;
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.action-buttons .el-button {
  padding: 12px 24px;
  font-size: 14px;
}

@media (max-width: 768px) {
  .error-container {
    padding: 40px 20px;
    margin: 20px;
  }

  .error-icon {
    font-size: 60px;
  }

  .error-content h2 {
    font-size: 20px;
  }

  .action-buttons {
    flex-direction: column;
    align-items: center;
  }

  .action-buttons .el-button {
    width: 100%;
    max-width: 200px;
  }
}
</style>
